#!/usr/local/bin/perl
use Module::CoreList;
use Data::Dumper;
use strict;

print<<END;
.if !defined(Perl_Depends_Include)

Perl_Depends_Include=\tbsd.perl.core.mk

END

foreach my $pver (sort keys %Module::CoreList::version)
{
  my $level = level($pver);

  print ".if \${PERL_LEVEL} == $level\n";
  foreach my $mod (sort keys %{$Module::CoreList::version{$pver}})
  {
    my $mver = $Module::CoreList::version{$pver}{$mod};
    $mver =~ s{\s+$}{};
    (my $name = $mod) =~ s{::}{_}g;
    printf("_perl_core_%s=\t%s\n", $name, $mver ? $mver : 0);
  }
  print ".endif # \${PERL_LEVEL} == $level\n\n";
}

print<<END;
.endif # Perl_Depends_Include
END

sub level
{
  my $pver = sprintf("%.06f", shift);
  my ($major, $minor, $patch) = ($1, $2, $3) if $pver =~ m{^(\d+)\.?(\d{0,3})(\d{0,3})$};
  return sprintf("%d%03d%02d", $major, $minor, $patch);
}
